package com.xbongbong.workflow.model.impl;

import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.workflow.domain.dao.WorkflowBackupRichTextDao;
import com.xbongbong.workflow.domain.entity.WorkflowBackupRichTextEntity;
import com.xbongbong.workflow.model.WorkflowBackupRichTextModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author bomfish
 */
@Service("workflowBackupRichTextModel")
public class WorkflowBackupRichTextModelImpl implements WorkflowBackupRichTextModel {
    @Resource
    private WorkflowBackupRichTextDao workflowBackupRichTextDao;

    @Override
    public Long insert(WorkflowBackupRichTextEntity entity) {
        return workflowBackupRichTextDao.insert(entity);
    }

    @Override
    public void insertBatch(List<WorkflowBackupRichTextEntity> list) {
        workflowBackupRichTextDao.insertBatch(list);
    }

    @Override
    public List<WorkflowBackupRichTextEntity> findEntities(Map<String, Object> param) {
        return workflowBackupRichTextDao.findEntities(param);
    }

    @Override
    public Integer getEntityCount(Map<String, Object> param) {
        return workflowBackupRichTextDao.getEntitiesCount(param);
    }

    @Override
    public void update(WorkflowBackupRichTextEntity entity) {
        workflowBackupRichTextDao.update(entity);
    }

    @Override
    public WorkflowBackupRichTextEntity getByKey(Long key, String corpid) {
        return workflowBackupRichTextDao.getByKey(key, corpid);
    }

    @Override
    public void updateByBackupId(WorkflowBackupRichTextEntity entity) {
        entity.setUpdateTime(DateTimeUtil.getInt());
        workflowBackupRichTextDao.updateByBackupId(entity);
    }

    @Override
    public WorkflowBackupRichTextEntity getByBackupId(Long backupId, String corpid) {
        return workflowBackupRichTextDao.getByBackupId(backupId, corpid);
    }

    @Override
    public boolean hasNoEmptyData(Map<String, Object> params) {
        Integer size = workflowBackupRichTextDao.countNoEmptyList(params);
        return size != 0;
    }

    @Override
    public Integer countNoEmptyData(Map<String, Object> params) {
        return workflowBackupRichTextDao.countNoEmptyList(params);
    }

    @Override
    public void deleteCompelete(String corpid, Long formId, List<Integer> delList, Integer afterDel) {
        Map<String, Object> params = new HashMap<>(BasicConstant.FIVE);
        params.put(StringConstant.CORPID, corpid);
        params.put(StringConstant.FORM_ID, formId);
        params.put(StringConstant.UPDATE_TIME, DateTimeUtil.getInt());
        params.put("delList", delList);
        params.put("afterDel", afterDel);
        workflowBackupRichTextDao.deleteComplete(params);
    }

}
